package com.mzw.huaxiarealestatebackend.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzw.huaxiarealestatebackend.dao.DepartmentDao;
import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.Department;
import com.mzw.huaxiarealestatebackend.service.DepartmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Department)表服务实现类
 *
 * @author makejava
 * @since 2023-12-11 16:21:55
 */
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService {
    @Resource
    private DepartmentDao departmentDao;

    @Override
    public List<Department> queryAll() {
        List<Department> departments = departmentDao.selectList(null);
        return departments;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param dpNo 主键
     * @return 实例对象
     */
    @Override
    public Department queryById(String dpNo) {
        QueryWrapper<Department> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dp_no", dpNo);
        Department department = departmentDao.selectOne(queryWrapper);
        return department;
    }


    /**
     * 新增数据
     *
     * @param department 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(Department department) {
        int insert = departmentDao.insert(department);
        return insert > 0;
    }

    /**
     * 修改数据
     *
     * @param department 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(Department department) {
        int update = departmentDao.update(department);
        return update > 0 ;
    }

    /**
     * 通过主键删除数据
     *
     * @param dpNo 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String dpNo) {
        int i = departmentDao.deleteById(dpNo);
        return i > 0;
    }
}
